const router = require('koa-router')();
const http = require("http");

/**
 * 得到swagger文档JSON数据
 */
router.get('/v2/api-docs', async (ctx, next) => {
    try {
        var opt = {
            host: 'localhost',
            port: global.COM_CONFIG.port,
            method: 'GET',
            path: '/swagger.json'
        }
        return await new Promise((r, j) => {
            http.request(opt, function (res) {
                res.setEncoding('utf-8');
                res.on('data', function (data) {
                    ctx.body = data;
                    return r();
                });
                res.on('error', function (e) { });
            }).on('error', function (e) {
                console.log("error: " + e.message);
            }).end();
        });
    } catch (e) { }
});


module.exports = router